<?php
namespace Cyfy\Modules\Users\Forms;

use \Cyfy\Message;
use \Cyfy\Modules\Forms;
use \Cyfy\Modules\Users\Current;
use \Cyfy\Modules\Users\Module;

/**
 * Add user to a group form.
 *
 * @author Dandelion <dandelion8888@gmail.com>
 * @version 0.1
 */
class AddUserToGroup extends Forms\Form {

    function structure()
    {
        $this -> permission("User", "groups and permissions");

        $i = new Forms\Select("gid", self :: t(100));
        $i -> data = \Cyfy\Modules\Users\Groups :: getAll(true);
        
        // unset logged and anonymous
        unset($i -> data[2]);
        unset($i -> data[3]);
        
        $this -> addItem($i);

        $b = new Forms\Button(self :: t(110), Forms\Button::OK);
        $this -> addButton($b);

        $this -> onSubmit = "Cyfy.ajax('Users', 'userGroups', '#userGroups', 'uid=" . $this -> getTemp("uid") . "')";
    }

    function submit()
    {
        $values = array(
            'uid' => $this -> getTemp('uid'),
            'gid' => $this -> get('gid')
        );  
    
        \dibi :: query("REPLACE INTO [:cyfy:Users-users-groups] %v", $values);
    }
}